function suggestAd(url, inputId, eid, titleLimit, bodyLimit)
{
	var desUrl = $.trim($(inputId).val());
	if(desUrl == '')
	{
		step1ErrorDesUrl(true);
		$(inputId).focus();
		return;
	}
	else
	{
		step1ErrorDesUrl(false);
	}
	
	if(isUrl(desUrl))
	{
		step1ErrorDesUrl(false);
		var onSuccess = function(data)
		{
			$(eid).html(data);
			var title = $.trim($('#step1_suggest_title').html());
			var bodytext = $.trim($('#step1_suggest_body').html());
				
			if(title != home_lang['example_ad_title'])
			{
				$('#title').val(title);
				$('#hddTitle').val(title);
				$('#errorTitle').hide();
				step1ErrorTitle(false);
				updateCountLimit('t', titleLimit);
			}
			else
			{
				step1ErrorTitle(true);
			}
			if(bodytext != home_lang['body_text_here'])
			{
				$('#step1BodyText').val(bodytext);
				$('#hddBodyText').val(bodytext);
				$('#errorBodyText').hide();
				step1ErrorBodyText(false);
				updateCountLimit('b', bodyLimit);
			}
			else
			{
				step1ErrorBodyText(true);
			}
			updateStep1Review();
			$('#imgSugLoading').css('display','none');
			setStyleClear('t');
			setStyleClear('b');
		};
		var currImage = $.trim($('#step1_suggest_image').attr('src'));
		getAjax(url, 'url=' + UrlEncode.encode(desUrl) + '&img=' + UrlEncode.encode(currImage), '', '', '', false, onSuccess);
		$('#imgSugLoading').css('display','');
	}
	else
	{
		step1ErrorDesUrl(true);
		$(inputId).focus();
		return;
	}
}

//Edit the counter/limiter value as your wish
function setp1_limiter(countLimit, eIdCheck, eIdStore, eIdCount, eIdShow, strDefault, errEId){
	var isShow = (typeof(eIdShow) === 'undefined' || eIdShow === '') ? false : true;
	var errEId = (typeof(errEId) === 'undefined' || errEId === '') ? '' : errEId;
	var tex = $(eIdCheck).val();
	var len = tex.length;
	var type = eIdCheck == '#title' ? 't' : 'b';
	setStyleClear(type);
	if(len > countLimit){
        tex = tex.substring(0,countLimit);
        $(eIdCheck).val(tex);
        $(eIdStore).val(tex);
        if(type == 't')
        {
        	$('#review_title').html(tex);
        	$('#review_adname').html(tex);
        }
        else
        {
        	$('#review_bodytext').html(tex);
        }
        if(isShow)
        {
        	$(eIdShow).html(tex);
        }
        return false;
	}
	
	$(eIdCount).html(countLimit-len);
	$(eIdStore).val(tex);
	if(type == 't')
    {
    	$('#review_title').html(tex);
    	$('#review_adname').html(tex);
    }
    else
    {
    	$('#review_bodytext').html(tex);
    }
	if(isShow)
    {
    	if(tex == '')
    	{
    		$(eIdShow).html(strDefault);
    		$(eIdShow + '_160').html(strDefault);
    	}
    	else
    	{
    		$(eIdShow).html(tex);
    		$(eIdShow + '_160').html(tex);
    	}
    }
	if(errEId != '')
	{
		if($.trim(tex) == '')
    	{
    		$(eIdCheck).addClass('error-border');
    		$(errEId).show();
    	}
    	else
    	{
    		$(eIdCheck).removeClass('error-border');
    		$(errEId).hide();
    	}
	}
}

function step1_desUrlKeyUp(eId, errEId)
{
	var tex = $.trim($(eId).val());
	if(tex == '')
	{
		step1ErrorDesUrl(true);
		$('#step1_domain').html('');
		$('#step1_domain_160').html('');
		$('#review_url').html('http://www.yourwebsite.com/');
	}
	else
	{
		if(!isUrl(tex))
		{
			step1ErrorDesUrl(true);
			$('#step1_domain').html($('#desUrl').val());
			$('#step1_domain_160').html($('#desUrl').val());
			$('#review_url').html($('#desUrl').val());
		}
		else
		{
			step1ErrorDesUrl(false);
			$('#step1_domain').html(getDomainFromUrl($('#desUrl').val()));
			$('#step1_domain_160').html(getDomainFromUrl($('#desUrl').val()));
			$('#review_url').html(getDomainFromUrl($('#desUrl').val()));
		}
		
	}
}

function move2Step(stepId, time)
{	
	time = (typeof(time) == 'undefined' || time == '') ? 1000 : time;
	$('html,body').animate({scrollTop: $(stepId).position().top}, time);
}

function step1ErrorTitle(isShow)
{
	if(isShow)
	{
		$('#title').addClass('error-border');
		$('#errorTitle').show();
	}
	else
	{
		$('#title').removeClass('error-border');
		$('#errorTitle').hide();
	}
}

function step1ErrorDesUrl(isShow)
{
	if(isShow)
	{
		$('#desUrl').addClass('error-border');
		$('#errorDesUrl').show();
	}
	else
	{
		$('#desUrl').removeClass('error-border');
		$('#errorDesUrl').hide();
	}
}

function step1ErrorBodyText(isShow)
{
	if(isShow)
	{
		$('#step1BodyText').addClass('error-border');
		$('#errorBodyText').show();
	}
	else
	{
		$('#step1BodyText').removeClass('error-border');
		$('#errorBodyText').hide();
	}
}

function step1ErrorImage(isShow)
{
	if(isShow)
	{
		$('#errorStep1Image').show();
	}
	else
	{
		$('#errorStep1Image').hide();
	}
}

function step1_continue_click()
{
	var desUrl = $.trim($('#desUrl').val());
	var chkUrl = true;
	if(!isUrl(desUrl) || desUrl == '')
	{
		step1ErrorDesUrl(true);
		checkBodyText = false;
	}
	else
	{
		step1ErrorDesUrl(false);
		checkBodyText = true;
	}
	
	var title = $.trim($('#title').val());
	var chkTitle = true;
	if(title == '')
	{
		step1ErrorTitle(true);
		chkTitle = false;
	}
	else
	{
		step1ErrorTitle(false);
		chkTitle = true;
	}
	
	var bodyText = $.trim($('#step1BodyText').val());
	var chkBtext = true;
	if(bodyText == '')
	{
		step1ErrorBodyText(true);
		chkBtext = false;
	}
	else
	{
		step1ErrorBodyText(false);
		chkBtext = true;
	}
	
	var imageFile = $.trim($('#hddFileName').val());
	var imgSrc = $.trim($('#step1_suggest_image').attr('src'));
	var chkImg = true;
	if(imageFile == '' || imgSrc == '')
	{
		step1ErrorImage(true);
		chkImg = false;
	}
	else
	{
		step1ErrorImage(false);
		chkImg = true;
	}
	
	if(chkUrl && chkBtext && chkImg && chkTitle)
	{
		$('#step1_continue').hide();
		updateLocationReview();
		$('#divStep2').show();
		showDivEstimate();
		move2Step('#divStep2', 1000);
	}
}

function step2_continue_click()
{
	
	var bac = ($('#chkBac').attr('checked')) ? '1' : '0';
	var trung = ($('#chkTrung').attr('checked')) ? '2' : '0';
	var nam = ($('#chkNam').attr('checked')) ? '3' : '0';
		
	var chkCity = ($.trim($('#txtTargetLocationCity').val()) == '') ? false : true;
	//var chkLike = ($.trim($('#txtTargetObject').val()) == '') ? false : true;
	var chkChannel = $.trim($('#hddListTargetSiteChannelId').val()) == '' ? false : true;
		
	if( (bac != '0' || trung != '0' || nam != '0' || chkCity) && chkChannel)
	{
	
		$('#step2_continue').hide();
		$('#divStep3').show();
		move2Step('#divStep3', 1000);
	
	}
	else
	{
		step2ShowLocationErr();
		step2ShowLikeErr();
		step2ShowSiteChannelError();
	}
	return;
}

function step2ShowLocationErr()
{
	var bac = ($('#chkBac').attr('checked')) ? '1' : '0';
	var trung = ($('#chkTrung').attr('checked')) ? '2' : '0';
	var nam = ($('#chkNam').attr('checked')) ? '3' : '0';
		
	var chkCity = ($.trim($('#txtTargetLocationCity').val()) == '') ? false : true;
	
	if( bac == '0' && trung == '0' && nam == '0' && !chkCity )
	{
		$('#errorLocation').show();
	}
	else
	{
		$('#errorLocation').hide();
	}
	
	return;
}

function step2ShowLikeErr()
{
	/*
	var chkLike = ($.trim($('#txtTargetObject').val()) == '') ? false : true;
	if(!chkLike)
	{
		$('#errorLike').show();
	}
	else
	{
		$('#errorLike').hide();
	}
	*/
	return;
}

function step2ShowSiteChannelError()
{
	
	var chkChannel = $.trim($('#hddListTargetSiteChannelId').val()) == '' ? false : true;
	if(!chkChannel)
	{	
		$('#errorSiteChannel').show();
	}
	else
	{	
		$('#errorSiteChannel').hide();
	}
	
	return;
}

function step3_showDivCampOption(opt)
{
	if(opt == 'create')
	{
		$('#endDate').val($('#campEndDate').val());
		$('#startDate').val($('#campStartDate').val());	
		$('#divChooseCamp').hide();
		$('#divCreateCamp').show();
		$('#hddCampType').val('create');
		
		updateCreateCampainReview();
	}
	else if(opt == 'choose')
	{
		$('#divChooseCamp').show();
		$('#divCreateCamp').hide();
		$('#hddCampType').val('choose');
		
		var campid = $('#step3SlcChooseCamp').val();
		chooseCampChange(campid);
		
		/*
		var currDate = new Date();
		var currMonth = currDate.getMonth() + 1;
		var currDay = currDate.getDate();
		var currYear = currDate.getFullYear();
		currMonth = (currMonth < 10) ? '0' + currMonth : currMonth;
		var strCurrDate = currDay + '-' + currMonth + '-' + currYear;
		
		$('#startDate').val(strCurrDate);
		
		var endDate = $('#hddChooseCampEndDate').val();
		if(endDate == '')
		{
			var campid = $('#step3SlcChooseCamp').val();
			chooseCampChange(campid);
		}
		else
		{
			$('#endDate').val($('#hddChooseCampEndDate').val());
			var startDate = new Date(currYear + '/' + currMonth + '/' + currDay);
		
			var arrEndDate = $('#endDate').val().split('-');
			var endDate = new Date(arrEndDate[2] + '/' + arrEndDate[1] + '/' + arrEndDate[0]);
			var numCampDay = ((endDate - startDate)/86400000) + 1;
			
			$('#review_num_camp_day').html(numCampDay);
			$('#review_camp_start').html(strCurrDate);
			$('#review_camp_end').html($('#endDate').val());
			
			$('#review_daily_budget').html($.trim($('#step3_ChooseCampBudget').html()));
		}
		$('#review_camp_name').html($.trim($("#step3SlcChooseCamp option[value=" + $("#step3SlcChooseCamp").val() + "]").text()));
		*/
	}
}

function chooseCampChange(value, editValue)
{
	editValue = (typeof(editValue) == 'undefined' || editValue == '') ? '' : editValue;
	if(editValue == '' || editValue != value)
	{
		var onsSuccess = function(data){
			var objData = jQuery.parseJSON(data);
			var maxValudDate = $.trim(objData.maxValueDay);
			maxValudDate += ' ' + home_lang['per_day'];
			var endDate = $.trim(objData.endDate);
			var arrEndDate = endDate.split('-');
			var startDate = $.trim(objData.startDate);
			var arrStartDate = startDate.split('-');
			
			var currDate = new Date();
			var currMonth = currDate.getMonth() + 1;
			var currDay = currDate.getDate();
			var currYear = currDate.getFullYear();
			currMonth = (currMonth < 10) ? '0' + currMonth : currMonth;
			var strCurrDate = currDay + '-' + currMonth + '-' + currYear;
			var currDate = new Date(currYear + '/' + currMonth + '/' + currDay);
			
			var endDateObj = new Date(arrEndDate[2] + '/' + arrEndDate[1] + '/' + arrEndDate[0]);
			var startDateObj = new Date(arrStartDate[2] + '/' + arrStartDate[1] + '/' + arrStartDate[0]);
			
			var numCampDay = 0;
			if(startDateObj > currDate)
			{
				$('#startDate').val(startDate);
				numCampDay = ((endDateObj - startDateObj)/86400000) + 1;
				$('#review_camp_start').html(startDate);
			}
			else
			{
				$('#startDate').val(strCurrDate);
				numCampDay = ((endDateObj - currDate)/86400000) + 1;
				$('#review_camp_start').html(strCurrDate);
			}
			
			$('#step3_ChooseCampBudget').html(maxValudDate);
			$('#endDate').val(endDate);
			
			$('#review_num_camp_day').html(numCampDay);
			$('#review_camp_end').html(endDate);
			
			$('#hddChooseCampEndDate').val(endDate);		
			$('#review_daily_budget').html(maxValudDate);
			$('#review_camp_name').html($.trim($("#step3SlcChooseCamp option[value=" + $("#step3SlcChooseCamp").val() + "]").text()));
		};
		getAjax('/home/get_campaign/' + value,'', '', '','', false, onsSuccess);
	}
}

function showDivCreateCampNameErr(isShow)
{
	if(isShow)
	{
		$('#txtCampName').addClass('error-border');
		$('#errorCreateCampName').show();
	}
	else
	{
		$('#txtCampName').removeClass('error-border');
		$('#errorCreateCampName').hide();
	}
}

function showDivCreateCampBudgetErr(isShow)
{
	if(isShow)
	{
		$('#txtCampBudget').addClass('error-border');
		$('#errorCreateCampBudget').show();
	}
	else
	{
		$('#txtCampBudget').removeClass('error-border');
		$('#errorCreateCampBudget').hide();
	}
}

function showDivCreateCampTimeErr(isShow)
{
	if(isShow)
	{
		//$('#campStartDate').addClass('error-border');
		//$('#campEndDate').addClass('error-border');
		$('#errorCreateCampTime').show();
	}
	else
	{
		//$('#campStartDate').removeClass('error-border');
		//$('#campEndDate').removeClass('error-border');
		$('#errorCreateCampTime').hide();
	}
}

function step3_create_camp_name_keyup()
{
	var tex = $.trim($('#txtCampName').val());
	if(tex != '')
	{
		showDivCreateCampNameErr(false);
	}
	else
	{
		showDivCreateCampNameErr(true);
	}
}

function step3_continue_click()
{
	var chooseCampType = $('#hddCampType').val();
	// check if add new campaign
	if(chooseCampType == 'create')
	{
		
		var arrStartDate = ($('#campStartDate').val()).split('-');
		var arrEndDate = ($('#campEndDate').val()).split('-');
		
		var startDate = new Date(arrStartDate[2] + '/' + arrStartDate[1] + '/' + arrStartDate[0]);
		var endDate = new Date(arrEndDate[2] + '/' + arrEndDate[1] + '/' + arrEndDate[0]);
		
		var chkTime = true;
		var chkName = true;
		var chkBudget = true;
		if(endDate < startDate)
		{
			showDivCreateCampTimeErr(true);
			chkTime = false;
		}
		else
		{
			chkTime = true;
			showDivCreateCampTimeErr(false);
		}
		
		var campName = $.trim($('#txtCampName').val());
		if(campName == '')
		{
			showDivCreateCampNameErr(true);
			chkName = false;
		}
		else
		{
			chkName = true;
			showDivCreateCampNameErr(false);
		}
		
		var campBudget = $('#txtCampBudget').val();
		campBudget = campBudget.replace(/,/gi,'');
		campBudget = parseFloat(campBudget);
		
		var budType = $('#slcCampBudgetType').val();
		
		if(budType == 'perday')
		{
			var numCampDay = ((endDate - startDate)/86400000) + 1;
			if((campBudget * numCampDay) < 100)
			{
				showDivCreateCampBudgetErr(true);
				chkBudget = false;
			}
			else
			{
				chkBudget = true;
				showDivCreateCampBudgetErr(false);
			}
		}
		else if(budType == 'lifetime')
		{
			if(campBudget < 100)
			{
				showDivCreateCampBudgetErr(true);
				chkBudget = false;
			}
			else
			{
				chkBudget = true;
				showDivCreateCampBudgetErr(false);
			}
		}
		//end check if add new campaign
		if(chkBudget && chkTime && chkName)
		{
			build_review();
			$('#step3_continue').hide();
			$('#divStep4').show();
			move2Step('#divStep4', 1000);
		}
	}
	else
	{
		build_review();
		$('#step3_continue').hide();
		$('#divStep4').show();
		move2Step('#divStep4', 1000);
	}
	
	return;
}

function build_review()
{
	// update ad review
	updateStep1Review();
	
	// update location review
	updateLocationReview();
	
	// update city reivew
	updateCityReview();
	
	// update cat like review
	updateCatReview();
	
	// update site review
	listSiteSort(false, false);
	
	// fill campaign name
	var chooseCampType = $('#hddCampType').val();
	if(chooseCampType == 'create')
	{	
		$('#review_camp_name').html($.trim($('#txtCampName').val()) + ' (' + home_lang['new_campaign'] + ')');
		
		var arrStartDate = ($('#campStartDate').val()).split('-');
		var arrEndDate = ($('#campEndDate').val()).split('-');
		
		var startDate = new Date(arrStartDate[2] + '/' + arrStartDate[1] + '/' + arrStartDate[0]);
		var endDate = new Date(arrEndDate[2] + '/' + arrEndDate[1] + '/' + arrEndDate[0]);
		
		var campBudget = $('#txtCampBudget').val();
		campBudget = campBudget.replace(/,/gi,'');
		campBudget = parseFloat(campBudget);
		
		var budType = $('#slcCampBudgetType').val();
		
		var numCampDay = ((endDate - startDate)/86400000) + 1;
		
		if(budType == 'perday')
		{
			$('#review_daily_budget').html( addCommas(campBudget.toString()) + ' ' + home_lang['per_day']);
		}
		else if(budType == 'lifetime')
		{
			
			var tmp = Math.round(campBudget / numCampDay);
			$('#review_daily_budget').html(addCommas(tmp.toString()) + ' ' + home_lang['per_day']);
		}
		
		//review duration
		$('#review_num_camp_day').html(numCampDay);
		$('#review_camp_start').html($('#campStartDate').val());
		$('#review_camp_end').html($('#campEndDate').val());
	}
	else
	{
    	$('#review_camp_name').html($.trim($("#step3SlcChooseCamp option[value=" + $("#step3SlcChooseCamp").val() + "]").text()));
		$('#review_daily_budget').html($.trim($('#step3_ChooseCampBudget').html()));
	}
}


function step4_continue(type)
{
	type = (typeof(type) === 'undefined' || type === '') ? 'create' : type;
	// check title
	if($.trim($('#hddTitle').val()) == '')
	{
		step1ErrorTitle(true);
		$('#title').focus();
		move2Step('#divStep1', 1000);
		return;
	}
	else
	{
		step1ErrorTitle(false);
	}
	
	// check des url
	var desUrl = $.trim($('#desUrl').val());
	if(desUrl == '' || !isUrl(desUrl))
	{
		step1ErrorDesUrl(true);
		$('#desUrl').focus();
		move2Step('#divStep1', 1000);
		return;
	}
	else
	{
		step1ErrorDesUrl(false);
	}
	
	// check body text
	if($.trim($('#hddBodyText').val()) == '')
	{
		step1ErrorBodyText(true);
		$('#step1BodyText').focus();
		move2Step('#divStep1', 1000);
		return;
	}
	else
	{
		step1ErrorBodyText(false);
	}
	
	// check image
	if($.trim($('#hddFileName').val()) == '')
	{
		step1ErrorImage(true);
		move2Step('#divStep1', 1000);
		return;
	}
	else
	{
		step1ErrorImage(false);
	}
	
	// check target location
	var bac = ($('#chkBac').attr('checked')) ? '1' : '0';
	var trung = ($('#chkTrung').attr('checked')) ? '2' : '0';
	var nam = ($('#chkNam').attr('checked')) ? '3' : '0';
	
	var chkCity = $.trim($('#txtTargetLocationCity').val()) == '' ? false : true;
	if(bac == '0' && trung == '0' && nam == '0' && !chkCity)
	{
		step2ShowLocationErr();
		move2Step('#divStep2', 1000);
		return;
	}
	else
	{
		step2ShowLocationErr();
	}
	
	// check target category
	/*
	var chkLike = $.trim($('#txtTargetObject').val()) == '' ? false : true;
	if(!chkLike )
	{
		step2ShowLikeErr();
		setTimeout('move2Step(\'#divStep2\')', 500);
		return;
	}
	else
	{
		step2ShowLikeErr();
	}
	*/
	// check site channel
	var chkSite = $.trim($('#hddListTargetSiteChannelId').val());
	if(!chkSite )
	{
		step2ShowSiteChannelError();
		move2Step('#divStep2', 1000);
		return;
	}
	else
	{
		step2ShowSiteChannelError();
	}
		
	var chooseCampType = $('#hddCampType').val();
	// check if add new campaign
	if(chooseCampType == 'create')
	{
		var arrStartDate = ($('#campStartDate').val()).split('-');
		var arrEndDate = ($('#campEndDate').val()).split('-');
		
		var startDate = new Date(arrStartDate[2] + '/' + arrStartDate[1] + '/' + arrStartDate[0]);
		var endDate = new Date(arrEndDate[2] + '/' + arrEndDate[1] + '/' + arrEndDate[0]);
		
		if(endDate < startDate)
		{
			showDivCreateCampTimeErr(true);
			$('#campEndDate').focus();
			move2Step('#divStep3', 1000);
			return;
		}
		else
		{
			showDivCreateCampTimeErr(false);
		}
		
		var campName = $.trim($('#txtCampName').val());
		if(campName == '')
		{
			showDivCreateCampNameErr(true);
			$('#txtCampName').focus();
			move2Step('#divStep3', 1000);
			return;
		}
		else
		{
			showDivCreateCampNameErr(false);
		}
		
		var campBudget = $('#txtCampBudget').val();
		campBudget = campBudget.replace(/,/gi,'');
		campBudget = parseFloat(campBudget);
		
		var budType = $('#slcCampBudgetType').val();
		
		if(budType == 'perday')
		{
			var numCampDay = ((endDate - startDate)/86400000) + 1;
			
			if((campBudget * numCampDay) < 100)
			{
				showDivCreateCampBudgetErr(true);
				$('#txtCampBudget').focus();
				move2Step('#divStep3', 1000);
				return;
			}
			else
			{
				showDivCreateCampBudgetErr(false);
			}
		}
		else if(budType == 'lifetime')
		{
			if(campBudget < 100)
			{
				showDivCreateCampBudgetErr(true);
				$('#txtCampBudget').focus();
				move2Step('#divStep3', 1000);
				return;
			}
			else
			{
				showDivCreateCampBudgetErr(false);
			}
		}
	}
	//end check if add new campaign
	if(type =='create')
	{
		//if(confirm('Are you sure create ad?'))
		//{
			$('#frmCreateAd').submit();
		//}
	}
	else if(type=='edit')
	{
		//if(confirm('Are you sure update ad?'))
		//{
			$('#frmCreateAd').submit();
		//}
	}
}

function initCreateAdFormField()
{
	// step 1
	if($('#slcBanner') != null)
	{
		$('#slcBanner').val(0);
	}
	
	$('#desUrl').val('');
	$('#title').val('');
	$('#hddTitle').val('');
	$('#step1BodyText').val('');
	$('#hddBodyText').val('');
	$('#hddFileName').val('');
	
	// step 2
	$('#chkLocationAll').attr('checked','checked');
	$('#chkBac').attr('checked','checked');
	$('#chkTrung').attr('checked','checked');
	$('#chkNam').attr('checked','checked');
	$('#chkLocationByCity').attr('checked','');
	
	$('#chkkAllSiteChannel').attr('checked','');
	
	// get estimate number
	updateEstimate();
	
	// step 3
	$('#txtCampName').val('');
	$('#txtCampBudget').val('100');
	$('#slcCampBudgetType').val('perday');
	
	var campid = $('#step3SlcChooseCamp').val();
	campid = campid == '' ? '0' : campid;
	
	var price = $.trim($('#hddCpcPrice').val());
	price = price.replace(/,/gi,'');
	var moneyUnitValue = $.trim($('#hddMoneyUnitValue').val());
	moneyUnitValue = moneyUnitValue.replace(/,/gi,'');
	
	price = parseInt(price);
	moneyUnitValue = parseInt(moneyUnitValue);
	
	$('#approximate_click').html(addCommas(parseInt((100 * moneyUnitValue)/price)));
	if(parseInt(campid) > 0)
	{
		chooseCampChange(campid);
	}
	else
	{
		var currDate = new Date();
		var currMonth = currDate.getMonth() + 1;
		currMonth = (currMonth < 10) ? '0' + currMonth : currMonth;
		var strCurrDate = currDate.getDate() + '-' + currMonth + '-' + currDate.getFullYear();
		$('#campStartDate').val(strCurrDate);
		$('#campEndDate').val(strCurrDate);
		$('#startDate').val(strCurrDate);
		$('#endDate').val(strCurrDate);
	}
}

function slcBannerChange(bid, maxTitle, maxBody)
{
	if(parseInt(bid) > 0)
	{
		var onSuccess = function(data)
		{
			$('#imgCopyAdLoading').css('display','none');
			
			var objData = jQuery.parseJSON(data);
			var title = $.trim(stripHtmlTags(objData.title));
			var btext = $.trim(stripHtmlTags(objData.desc));
			var url = $.trim(objData.url);
			var filePath = $.trim(objData.img);
			var fileName = $.trim(objData.filename);
			$('#desUrl').val(url);
			if(url != '')
			{
				$('#errorDesUrl').hide();
				//$('#desUrl').removeClass('error-border');
			}
			else
			{
				$('#errorDesUrl').show();
				//$('#desUrl').addClass('error-border');
			}
			
			$('#step1_suggest_title').html(title);
			$('#step1_suggest_title_160').html(title);
			$('#title').val(title);
			$('#hddTitle').val(title);
			if(title != '')
			{
				$('#errorTitle').hide();
				//$('#title').removeClass('error-border');
			}
			else
			{
				$('#errorTitle').show();
				//$('#title').addClass('error-border');
			}
			
			$('#step1_suggest_body').html(btext);
			$('#step1_suggest_body_160').html(btext);
			$('#step1BodyText').val(btext);
			$('#hddBodyText').val(btext);
			if(btext != '')
			{
				$('#errorBodyText').hide();
				//$('#step1BodyText').removeClass('error-border');
			}
			else
			{
				$('#errorBodyText').show();
				//$('#step1BodyText').addClass('error-border');
			}
			
			if(filePath != '')
			{
				$('#step1_suggest_image').attr('src', filePath).show();
				$('#step1_suggest_image_160').attr('src', filePath).show();
				$('#review_image').attr('src', filePath).show();
				$('#hddFileName').val(fileName);
				
				$('#errorStep1Image').hide();
			}
			updateCountLimit('t', maxTitle);
			updateCountLimit('b', maxBody);
			updateStep1Review();
			setStyleClear('t');
			setStyleClear('b');
			
		};
		
		var onError = function(jqXHR, textStatus, errorThrown)
		{
			$('#imgCopyAdLoading').css('display','none');
			
		};
		
		var onComplete = function(jqXHR, textStatus)
		{
			$('#imgCopyAdLoading').css('display','none');
		};
		
		$('#imgCopyAdLoading').css('display','');
		getAjax('/home/suggest_banner/' + bid, '', '', '', '', false, onSuccess, onError, onComplete);
	}
}

function updateStep1Review()
{
	$('#review_title').html($('#hddTitle').val());
	$('#step1_domain').html( getDomainFromUrl($('#desUrl').val()));
	$('#step1_domain_160').html( getDomainFromUrl($('#desUrl').val()));
	$('#review_url').html( getDomainFromUrl($('#desUrl').val()));
	$('#review_image').attr('src',$('#step1_suggest_image').attr('src'));
	$('#review_bodytext').html($('#hddBodyText').val());
	$('#review_adname').html($('#hddTitle').val());
}

function updateCountLimit(opt, limit)
{
	if(opt == 't')
	{
		var numText = $('#title').val().length;
		$('#titleLimit').html(limit - numText);
	}
	else if(opt == 'b')
	{
		var numText = $('#step1BodyText').val().length;
		$('#bodyTextLimit').html(limit - numText);
	}
}

function chkLocationAllClick()
{
	
	var checked = $('#chkLocationAll').attr('checked') ? 'checked' : '';
	$('.chkLocation').attr('checked',checked);
	
	step2ShowLocationErr();
	updateLocationReview();
	updateEstimate();
}

function chLocationItemClick()
{
	var arrLocaItem = $('.chkLocation');
	var chkall = true;
	for(var i = 0; i <arrLocaItem.length; i++)
	{
		if(!$(arrLocaItem[i]).attr('checked'))
		{
			chkall = false;
			break;
		}
	}
		
	if(chkall)
	{
		$('#chkLocationAll').attr('checked', 'checked');
		step2ShowLocationErr();
	}
	else
	{
		var chk = true;
		for(var i = 0; i <arrLocaItem.length; i++)
		{
			if($(arrLocaItem[i]).attr('checked'))
			{
				chk = false;
				break;
			}
		}
		
		$('#chkLocationAll').attr('checked', '');
		step2ShowLocationErr(chk);
	}
	
	updateLocationReview();
	updateEstimate();
}

function updateLocationReview()
{
	var strLocation = '';
	if($('#chkBac').attr('checked'))
	{
		strLocation += '<li>' + $.trim($('#bacName').html()) + '</li>';
	}
	if($('#chkTrung').attr('checked'))
	{
		strLocation += '<li>' + $.trim($('#trungName').html()) + '</li>';
	}
	if($('#chkNam').attr('checked'))
	{
		strLocation += '<li>' + $.trim($('#namName').html()) + '</li>';
	}
	$('#review_location').html(strLocation);
	$('#estimate-location').html(strLocation);
	
	if(strLocation != '')
	{
		$('#divEstimateLocation').css('display', '');
		$('#trReviewLocation').css('display', '');
	}
	else
	{
		$('#divEstimateLocation').css('display', 'none');
		$('#trReviewLocation').css('display', 'none');
	}
}

function updateCityReview()
{
	var arrSelectedTag = $('#txtTargetLocationCity').parent('.superblyTagInputItem').parent('.superblyTagItems').children(".superblyTagItem");
	var numSelectedTag = arrSelectedTag.length;

	var strReviewCity = '';
	var strEsitmateCity = '';
	var numSiteCheck = 0;
	for(var i=0; i<numSelectedTag; i++)
	{
		var name = ($(arrSelectedTag[i]).find('span').html());
		var style = (i < 5) ? '' : 'display:none;';
		strReviewCity += '<li class="liCityReview" style="' + style + '">' + name + '</li>';
		strEsitmateCity += '<li class="liCityEstimate" style="' + style + '">' + name + '</li>';
		numSiteCheck++;
	}
	
	if(numSiteCheck > 5)
	{
		strReviewCity += '<li class="expand" id="liCityReviewExpand" onclick="cityReviewExpand();" >'+ home_lang['expand'] +'</li>';
		strEsitmateCity += '<li class="expand" id="liCityEstimateExpand" onclick="cityEstimateExpand();" >' + home_lang['expand'] + '</li>';
	}	
	
	$('#review_city').html(strReviewCity);
	$('#estimate-location-city').html(strEsitmateCity);
	
	if(numSiteCheck > 0)
	{
		$('#divEstimateCity').css('display', '');
		$('#trReviewCity').css('display', '');
	}
	else
	{
		$('#divEstimateCity').css('display', 'none');
		$('#trReviewCity').css('display', 'none');
	}
}

function cityEstimateExpand()
{		
	if($('#liCityEstimateExpand').hasClass('expand'))
	{
		var arr = $('#estimate-location-city li.liCityEstimate');
		var num = arr.length;
		if(num > 4)
		{
			for(var i = 5; i < num; i++)
			{
				$(arr[i]).show();
			}
		}
				
		$('#liCityEstimateExpand').html(home_lang['collapse']);
		$('#liCityEstimateExpand').removeClass('expand');
		$('#liCityEstimateExpand').addClass('collaspe');
	}
	else if($('#liCityEstimateExpand').hasClass('collaspe'))
	{
		var arr = $('#estimate-location-city li.liCityEstimate');
		var num = arr.length;
		if(num > 4)
		{
			for(var i = 5; i < num; i++)
			{
				$(arr[i]).hide();	
			}
		}
		
		$('#liCityEstimateExpand').html(home_lang['expand']);
		$('#liCityEstimateExpand').removeClass('collaspe');
		$('#liCityEstimateExpand').addClass('expand');
	}
	scrollEstimateBox();
}

function cityReviewExpand()
{
	if($('#liCityReviewExpand').hasClass('expand'))
	{
		var arr = $('#review_city li.liCityReview');
		var num = arr.length;
		if(num > 4)
		{
			for(var i = 5; i < num; i++)
			{
				$(arr[i]).show(250);
			}
		}
		$('#liCityReviewExpand').html(home_lang['collapse']);
		$('#liCityReviewExpand').removeClass('expand');
		$('#liCityReviewExpand').addClass('collaspe');
	}
	else if($('#liCityReviewExpand').hasClass('collaspe'))
	{
		var arr = $('#review_city li.liCityReview');
		var num = arr.length;
		if(num > 4)
		{
			for(var i = 5; i < num; i++)
			{
				$(arr[i]).hide(250);
			}
		}
		$('#liCityReviewExpand').html(home_lang['expand']);
		$('#liCityReviewExpand').removeClass('collaspe');
		$('#liCityReviewExpand').addClass('expand');
	}
	scrollEstimateBox();
}


function updateCatReview()
{
	var arrSelectedTag = $('#txtTargetObject').parent('.superblyTagInputItem').parent('.superblyTagItems').children(".superblyTagItem");
	var numSelectedTag = arrSelectedTag.length;
	
	var strReviewCat = '';
	var strEsitmateCat = '';
	var numSiteCheck = 0;
	for(var i=0; i<numSelectedTag; i++)
	{
		var name = ($(arrSelectedTag[i]).find('span').html());
		var style = (i < 5) ? '' : 'display:none;';
		strReviewCat += '<li class="liCatReview" style="' + style + '">' + name + '</li>';
		strEsitmateCat += '<li class="liCatEstimate" style="' + style + '">' + name + '</li>';
		numSiteCheck++;
	}
	
	if(numSiteCheck > 5)
	{
		strReviewCat += '<li class="expand" id="liCatReviewExpand" onclick="catReviewExpand();" >'+ home_lang['expand'] +'</li>';
		strEsitmateCat += '<li class="expand" id="liCatEstimateExpand" onclick="catEstimateExpand();" >' + home_lang['expand'] + '</li>';
	}
	$('#review_like').html(strReviewCat);
	$('#estimate-like').html(strEsitmateCat);
	
	if(numSiteCheck > 0)
	{
		$('#divEstimateCat').css('display', '');
		$('#trReviewCat').css('display', '');
	}
	else
	{
		$('#divEstimateCat').css('display', 'none');
		$('#trReviewCat').css('display', 'none');
	}
}

function scrollEstimateBox()
{
	var footerPos = $('#footer-inner').position();
	var estimatePos = $('#divEstimate').position();
	var estimateHeight = $('#divEstimate').height();
	var top = estimatePos.top;
	
	if(estimatePos.top + estimateHeight > footerPos.top)
	{
		top = (footerPos.top - estimateHeight);
		//top = (top < 0) ? 0 : top;
		top = top - 5;
		$("#divEstimate").stop().animate({"top": top + "px"}, 500);
	}
	else
	{
		var tmpStep2Pos = $('#divStep2').position();
		if($(window).scrollTop() <= tmpStep2Pos.top)
		{
			top = tmpStep2Pos.top;
		}
		else
		{
			top = $(window).scrollTop();
		}
		if(top + estimateHeight <= footerPos.top)
		{
			$("#divEstimate").stop().animate({"top": top + "px"}, 500);
		}
		else
		{
			top = top - (top + estimateHeight - footerPos.top);
			$("#divEstimate").stop().animate({"top": top + "px"}, 500);
		}
	}
}

function catEstimateExpand()
{	
	if($('#liCatEstimateExpand').hasClass('expand'))
	{
		var arr = $('#estimate-like li.liCatEstimate');
		var num = arr.length;
		if(num > 4)
		{
			for(var i = 5; i < num; i++)
			{
				$(arr[i]).show();
			}
		}
				
		$('#liCatEstimateExpand').html(home_lang['collapse']);
		$('#liCatEstimateExpand').removeClass('expand');
		$('#liCatEstimateExpand').addClass('collaspe');
	}
	else if($('#liCatEstimateExpand').hasClass('collaspe'))
	{
		var arr = $('#estimate-like li.liCatEstimate');
		var num = arr.length;
		if(num > 4)
		{
			for(var i = 5; i < num; i++)
			{
				$(arr[i]).hide();	
			}
		}
			
		$('#liCatEstimateExpand').html(home_lang['expand']);
		$('#liCatEstimateExpand').removeClass('collapse');
		$('#liCatEstimateExpand').addClass('expand');
	}
	scrollEstimateBox();	
}


function catReviewExpand()
{
	if($('#liCatReviewExpand').hasClass('expand'))
	{
		var arr = $('#review_like li.liCatReview');
		var num = arr.length;
		if(num > 4)
		{
			for(var i = 5; i < num; i++)
			{
				$(arr[i]).show(250);
			}
		}
		$('#liCatReviewExpand').html(home_lang['collapse']);
		$('#liCatReviewExpand').removeClass('expand');
		$('#liCatReviewExpand').addClass('collaspe');
	}
	else if($('#liCatReviewExpand').hasClass('collaspe'))
	{
		var arr = $('#review_like li.liCatReview');
		var num = arr.length;
		if(num > 4)
		{
			for(var i = 5; i < num; i++)
			{
				$(arr[i]).hide(250);
			}
		}
		$('#liCatReviewExpand').html(home_lang['expand']);
		$('#liCatReviewExpand').removeClass('collaspe');
		$('#liCatReviewExpand').addClass('expand');
	}
	scrollEstimateBox();
}

function siteEstimateExpand()
{		
	if($('#liSiteEstimateExpand').hasClass('expand'))
	{
		var arr = $('#estimate-site li.liSiteEstimate');
		var num = arr.length;
		if(num > 4)
		{
			for(var i = 5; i < num; i++)
			{
				$(arr[i]).show();
			}
		}
		$('#liSiteEstimateExpand').html(home_lang['collapse']);
		$('#liSiteEstimateExpand').removeClass('expand');
		$('#liSiteEstimateExpand').addClass('collaspe');
	}
	else if($('#liSiteEstimateExpand').hasClass('collaspe'))
	{
		var arr = $('#estimate-site li.liSiteEstimate');
		var num = arr.length;
		if(num > 4)
		{
			for(var i = 5; i < num; i++)
			{
				$(arr[i]).hide();	
			}
		}
		$('#liSiteEstimateExpand').html(home_lang['expand']);
		$('#liSiteEstimateExpand').removeClass('collaspe');
		$('#liSiteEstimateExpand').addClass('expand');
	}
	scrollEstimateBox();	
}

function siteReviewExpand()
{
	if($('#liSiteReviewExpand').hasClass('expand'))
	{
		var arr = $('#review_site li.liSiteReview');
		var num = arr.length;
		if(num > 4)
		{
			for(var i = 5; i < num; i++)
			{
				$(arr[i]).show(250);
			}
		}
		$('#liSiteReviewExpand').html(home_lang['collapse']);
		$('#liSiteReviewExpand').removeClass('expand');
		$('#liSiteReviewExpand').addClass('collaspe');
	}
	else if($('#liSiteReviewExpand').hasClass('collaspe'))
	{
		var arr = $('#review_site li.liSiteReview');
		var num = arr.length;
		if(num > 4)
		{
			for(var i = 5; i < num; i++)
			{
				$(arr[i]).hide(250);
			}
		}
		$('#liSiteReviewExpand').html(home_lang['expand']);
		$('#liSiteReviewExpand').removeClass('collaspe');
		$('#liSiteReviewExpand').addClass('expand');
	}
	scrollEstimateBox();
}

function btnEditAdClick()
{
	//$('#step1_continue').show();
	//$('#step2_continue').show();
	//$('#step3_continue').show();
	move2Step('#divStep1', 2000);
}

function updateCreateCampainReview()
{
	var price = $.trim($('#hddCpcPrice').val());
	price = price.replace(/,/gi,'');
	var moneyUnitValue = $.trim($('#hddMoneyUnitValue').val());
	moneyUnitValue = moneyUnitValue.replace(/,/gi,'');
	
	price = parseInt(price);
	moneyUnitValue = parseInt(moneyUnitValue);
	
	
	
	
	$('#review_camp_name').html($.trim($('#txtCampName').val()) + ' (' + home_lang['new_campaign'] + ')');
	
	
	var strStartDate = $('#campStartDate').val();
	var strEndDate = $('#campEndDate').val();
	var arrStartDate = strStartDate.split('-');
	var arrEndDate = strEndDate.split('-');
	
	var startDate = new Date(arrStartDate[2] + '/' + arrStartDate[1] + '/' + arrStartDate[0]);
	var endDate = new Date(arrEndDate[2] + '/' + arrEndDate[1] + '/' + arrEndDate[0]);
	
	var campBudget = $('#txtCampBudget').val();
	campBudget = campBudget.replace(/,/gi,'');
	campBudget = parseFloat(campBudget);
	
	$('#approximate_click').html(addCommas(parseInt((campBudget * moneyUnitValue)/price)));
	
	if(campBudget < 100)
	{
		$('#errorCreateCampBudget').show();
	}
	else
	{
		$('#errorCreateCampBudget').hide();
	}
	
	var budType = $('#slcCampBudgetType').val();
	
	var numCampDay = ((endDate - startDate)/86400000) + 1;
	if(budType == 'perday')
	{
		$('#review_daily_budget').html(addCommas(campBudget.toString()) + ' ' + home_lang['per_day']);
	}
	else if(budType == 'lifetime')
	{
		
		//var tmp = Math.round(campBudget / numCampDay);
		$('#review_daily_budget').html(addCommas(campBudget.toString()) + ' ' + home_lang['life_time']);
	}
	
	$('#review_num_camp_day').html(numCampDay);
	$('#review_camp_start').html(strStartDate);
	$('#review_camp_end').html(strEndDate);
}

function updateEstimate()
{
	var strLocationId = '';
	if($('#chkBac').attr('checked'))
	{
		strLocationId += (strLocationId == '') ? '1' : ',1';
	}
	if($('#chkTrung').attr('checked'))
	{
		strLocationId += (strLocationId == '') ? '2' : ',2';
	}
	if($('#chkNam').attr('checked'))
	{
		strLocationId += (strLocationId == '') ? '3' : ',3';
	}
	
	var strCityId = $('#txtTargetLocationCity').val();
	var strCatId = $('#txtTargetObject').val();
	var strChannelId = $('#hddListTargetSiteChannelId').val();
	
	var onSuccess = function(data)
	{
		var objData = jQuery.parseJSON(data);
		var estimateNumber = $.trim(objData.estimate);
		$('#estimate-number').html(estimateNumber);
		$('#estimateLoading').css('display','none');
	};
	$('#estimateLoading').css('display','');
	getAjax('/home/estimate/?locat=' + strLocationId + '&city=' + strCityId + '&cat=' + strCatId + '&channel=' + strChannelId, '', '', '', '', false, onSuccess);
}

function showDivEstimate()
{
	var divStep2Pos = $('#divStep2').position();
	$("#divEstimate").css({top: divStep2Pos.top + 'px', left: (divStep2Pos.left + 753) + 'px' }) ;
	$('#divEstimate').show();
}


/*
function checkSiteByCat()
{
	var arrLike = $('.chkLikeClass');
	var strLike = '';
	var strLikeId = '';
	for(var i=0; i < arrLike.length; i++)
	{
		if($(arrLike[i]).attr('checked'))
		{
			strLikeId += (strLikeId == '') ? $(arrLike[i]).val() : ',' + $(arrLike[i]).val();
		}
	}
	
	var onSuccess = function(data)
	{
		var objData = jQuery.parseJSON(data);
		var strListSite = $.trim(objData.lstsite);
		var arrSite = strListSite.split(',');
		var numSite = arrSite.length;
		for(var i = 0; i < numSite; i++)
		{
			if(arrSite[i] != '')
			{
				$('input#siteItem_' + arrSite[i]).attr('checked', 'checked');
				$('input#siteItem_' + arrSite[i]).attr('disabled', 'disabled');
				$('#siteNameClass_' + arrSite[i]).addClass('text-gray');
			}
		}
		if(numSite > 0)
		{
			var arrSite = $('.chkSiteClass');
			var strSite = '';
			var strSiteId = '';
			strListSite = strListSite + ',';
			var numSiteCheck = 0;
			for(var i=0; i < arrSite.length; i++)
			{
				var valId = $(arrSite[i]).val();
				if(strListSite.indexOf(valId + ",") == -1)
				{
					if($(arrSite[i]).attr('disabled'))
					{
						$(arrSite[i]).attr('disabled', '');
						$(arrSite[i]).attr('checked', '');
						$('#siteNameClass_' + valId).removeClass('text-gray');
					}
				}
				if($(arrSite[i]).attr('checked'))
				{
					var style = (i < 6) ? '' : 'display:none;';
					var siteName = $.trim($('#siteNameClass_' +$(arrSite[i]).val()).html());
					strSite += '<li class="liSiteEstimate" style="' + style + '">' + siteName + '</li>';
					numSiteCheck++;				
				}
			}
			
			if(numSiteCheck > 5)
			{
				strSite += '<li class="cursor-pointer bold" id="liSiteEstimateExpand" onclick="siteEstimateExpand();" style="color: #09659a;list-style: none;margin-left: 0;" >' + home_lang['expand'] + '</li>';
			}
			
			$('#estimate-site').html(strSite);
			$('#review_site').html(strSite);
		}
	};
	
	getAjax('/home/getcatsite/?like=' + strLikeId, '', '', '', '', false, onSuccess);
}
*/

// for new
function showTargetByCity(obj, eId)
{
	if($(obj).attr('checked'))
	{
		$(eId).show();
	}
	else
	{
		$(eId).hide();
	}
}


function expandSiteChannel(divOuterId, classname, obj, aSiteExpandId)
{
	var className = $(obj).attr('class');
	if(className == 'img-site-expand')
	{
		$(divOuterId + ' .' + classname).show(300);
		$(obj).attr('class', 'img-site-collapse');
		$(aSiteExpandId).attr('class', 'a-site-collapse');
		//$(obj).attr('src', '/images/imgcollapse.gif');
	}
	else if(className == 'img-site-collapse')
	{
		var arr = $(divOuterId + ' .' + classname);
		var num = arr.length;
		if(num > 4)
		{
			for(var i=4; i < num; i++)
			{
				$(arr[i]).hide(300);
			}
		}
		$(obj).attr('class', 'img-site-expand');
		//$(obj).attr('src', '/images/imgexpand.gif');
		$(aSiteExpandId).attr('class', 'a-site-expand');
	}
}

function expandSiteChannelAll(divOuterId, classname, imgExpandName, obj)
{
	var className = $(obj).attr('class');
	if(className == 'a-site-expand')
	{
		$(divOuterId + ' .' + classname).show(300);
		$(obj).attr('class', 'a-site-collapse');
		$(divOuterId + ' .' + imgExpandName).find('img').attr('class', 'img-site-collapse');
	}
	else if(className == 'a-site-collapse')
	{
		var arr = $(divOuterId + ' .' + classname);
		var num = arr.length;
		if(num > 4)
		{
			for(var i=4; i < num; i++)
			{
				$(arr[i]).hide(300);
			}
		}
		$(obj).attr('class', 'a-site-expand');
		$(divOuterId + ' .' + imgExpandName).find('img').attr('class', 'img-site-expand');
	}
}

function channelItemCheck(obj)
{
	var strCurrChalId = $.trim($('#hddListTargetSiteChannelId').val());
	var arrCurrChalId = new Array();
	if(strCurrChalId != '')
	{
		arrCurrChalId = strCurrChalId.split(',');
	}
	//console.info(arrCurrChalId.join(','));
	var id = $(obj).val();
	if($(obj).attr('checked'))
	{
		if(jQuery.inArray(id,arrCurrChalId) == -1)
		{
			arrCurrChalId.push(id);
		}
		//console.info(arrCurrChalId.join(','));
		$('#hddListTargetSiteChannelId').val(arrCurrChalId.join(','));
	}
	else
	{
		var index = jQuery.inArray(id,arrCurrChalId);
		if( index > -1)
		{
			arrCurrChalId.splice(index,1);
		}
		$('#hddListTargetSiteChannelId').val(arrCurrChalId.join(','));
	}
	updateEstimate();
	listSiteSort(false, false);
	
	step2ShowSiteChannelError();
}

function checkAllSiteChannel(divOuterId, classname, obj)
{
	var strCurrChalId = $.trim($('#hddListTargetSiteChannelId').val());
	var arrCurrChalId = new Array()
	if(strCurrChalId != '')
	{
		arrCurrChalId = strCurrChalId.split(',');
	} 
	if($(obj).hasClass('chkall'))
	{
		var arrChal = $(divOuterId + ' .' + classname);
		var numChal = arrChal.length;
		for(var i=0; i < numChal; i++)
		{
			var id = $(arrChal[i]).val();
			if(jQuery.inArray(id,arrCurrChalId) == -1)
			{
				arrCurrChalId.push(id);
			}
			$(arrChal[i]).attr('checked', 'checked');
		}
		$('#hddListTargetSiteChannelId').val(arrCurrChalId.join(','));
		$(obj).removeClass('chkall');
		$(obj).addClass('chkunall');
		
	}
	else if($(obj).hasClass('chkunall'))
	{
		var arrChal = $(divOuterId + ' .' + classname);
		var numChal = arrChal.length;
		for(var i=0; i < numChal; i++)
		{
			var id = $(arrChal[i]).val();
			var index = jQuery.inArray(id,arrCurrChalId);
			if( index > -1)
			{
				arrCurrChalId.splice(index,1);
			}
			$(arrChal[i]).attr('checked', '');
		}
		$('#hddListTargetSiteChannelId').val(arrCurrChalId.join(','));
		$(obj).removeClass('chkunall');
		$(obj).addClass('chkall');
	}
	updateEstimate();
	listSiteSort(false, false);
	step2ShowSiteChannelError();
}

function checkAllChannel(obj)
{
	if($(obj).attr('checked'))
	{
		var arrChannel = $('#divTargetSiteBox .chksitechannel');
		var numChannel = arrChannel.length;
		var arrChannelId = new Array();
		for(var i = 0; i < numChannel; i++)
		{
			arrChannelId.push($(arrChannel[i]).val());
			$(arrChannel[i]).attr('checked', 'checked');
		}
		$('#hddListTargetSiteChannelId').val(arrChannelId.join(','));
		updateEstimate();
	}
	else
	{
		$('#divTargetSiteBox .chksitechannel').attr('checked', '');
		$('#hddListTargetSiteChannelId').val('');
		updateEstimate();
	}
	listSiteSort(false, false);
	step2ShowSiteChannelError();
}

function expandSite(boxId, expId, colId, classname, type)
{
	if(type == 1)
	{
		$(boxId + ' ' + classname).show(300);
		$(expId).hide();
		$(colId).show();
	}
	else if(type == 2)
	{
		listSiteSort(false, true, true);
		/*
		var arr = $(boxId + ' ' + classname);
		var num = arr.length;
		if(num > 4)
		{
			for(var i=4; i < num; i++)
			{
				$(arr[i]).hide(300);
			}
		}
		$(expId).show();
		$(colId).hide();
		*/
	}
	scrollEstimateBox();
}

function listSiteSort(isReturnListChannelId, isSort, isCollapse)
{
	isReturnListChannelId = (typeof(isReturnListChannelId) === 'undefined' || isReturnListChannelId === '') ? false : isReturnListChannelId;
	isSort = (typeof(isSort) === 'undefined' || isSort === '') ? true : isSort;
	isCollapse = (typeof(isCollapse) === 'undefined' || isCollapse === '') ? false : isCollapse;
	var arrSiteBox = $('#divTargetSiteBox .divSiteOuter');
	var num = arrSiteBox.length;
	var arrHasSelected = new Array();
	var arrNoSelected = new Array();
	var arrValueChecked = new Array();
	var arrSiteName = new Array();
	
	//var arrHasSelectedIndex = new Array();
	//var arrNoSelectedIndex = new Array();
	
	for(var i = 0; i < num; i++)
	{
		var arrChk = $(arrSiteBox[i]).find('input.chksitechannel');
		var numCheck = arrChk.length;
		var chkItem = false;
		for(var j=0; j < numCheck; j++)
		{
			if($(arrChk[j]).attr('checked'))
			{
				chkItem = true;
				break;
			}
		}
		if(chkItem)
		{
			var tdChlOuter = $(arrSiteBox[i]).find('.tdChlOuter');
			var arrChalItem = $(tdChlOuter[0]).find('.target-site-channel');
			arrSiteName.push($(arrSiteBox[i]).find('.trg-site-name').html());
			var numChlItem = arrChalItem.length;
			var arrSlc = new Array();
			var arrNoSlc = new Array();
			var tmpIndex = 0;
		 	for(var k=0; k < numChlItem; k++)
		 	{
		 		if($(arrChalItem[k]).children('.chksitechannel').attr('checked'))
		 		{
		 			//var tmpk = arrChalItem[k];
		 			if(tmpIndex < 4)
			 		{
			 			$(arrChalItem[k]).css('display','');
			 			tmpIndex++;
			 		}
			 		else
			 		{
			 			$(arrChalItem[k]).css('display', 'none');
			 		}
			 		//arrChalItem[k] = tmpk;
			 		arrValueChecked.push($(arrChalItem[k]).children('.chksitechannel').val());
		 			arrSlc.push(arrChalItem[k]);
		 		}
		 		else
		 		{
		 			
		 			$(arrChalItem[k]).css('display', 'none');
			 		arrNoSlc.push(arrChalItem[k]);
		 		}		 		
		 	}
	 		if(tmpIndex < 4 && arrNoSlc.length > 0)
	 		{
	 			for(var k = 0; k < arrNoSlc.length; k++)
	 			{
	 				if(tmpIndex < 4)
	 				{
	 					$(arrNoSlc[k]).css('display','');
	 				}
	 				else
	 				{
	 					$(arrNoSlc[k]).css('display','none');
	 					//break;
	 				}
	 				tmpIndex++;
	 			}
	 		}
		 	$(tdChlOuter).html(jQuery.merge(arrSlc, arrNoSlc));
		 	arrHasSelected.push(arrSiteBox[i]);
		 	//arrHasSelectedIndex.push(i);
		}
		else
		{
			arrNoSelected.push(arrSiteBox[i]);
			//arrNoSelectedIndex.push(i);
		}
	}
	if(isSort)
	{
		//var totalArr = jQuery.merge(arrHasSelected, arrNoSelected);
		if($('#tgr-site-expand').css('display') != 'none' || isCollapse)
		{
			//alert($('#tgr-site-expand').css('display'));
			var numSiteBoxHasSelected = arrHasSelected.length;
			var numSiteBoxNotSelected = arrNoSelected.length;
			var i_temp = 0;
			for(var i=0; i < numSiteBoxHasSelected; i++)
			{
				if(i < 4)
				{
					$(arrHasSelected[i]).css('display', '');
					i_temp++;
				}
				else
				{
					$(arrHasSelected[i]).css('display', 'none');
				}
			}
			
			for(var i = 0; i < numSiteBoxNotSelected; i++)
			{
				if(i_temp < 4)
				{
					$(arrNoSelected[i]).css('display', '');
				}
				else
				{
					$(arrNoSelected[i]).css('display', 'none');
				}
				i_temp++;
			}
			
		}

		//$('#divTargetSiteBox').html(totalArr);
		
		for(var i = 0; i < arrValueChecked.length; i++)
		{
			$('#site-channel-' + arrValueChecked[i]).attr('checked', 'checked');
			//$('#site-channel-' + arrValueChecked[i]).parent('p.target-site-channel').css('display', '');
		}
	}
		
	
	// update estimate site + update step 4 review site
	var numSlcSite = arrSiteName.length;
	var numSiteCheck = 0;
	var strSiteReview = '';
	var strSiteEstimate = '';
	for(var i=0; i < numSlcSite; i++)
	{
		var style = (i < 5) ? '' : 'display:none;';
		strSiteReview += '<li class="liSiteReview" style="' + style + '">' + arrSiteName[i] + '</li>';
		strSiteEstimate += '<li class="liSiteEstimate" style="' + style + '">' + arrSiteName[i] + '</li>';
		numSiteCheck++;
	}
	
	if(numSiteCheck > 5)
	{
		strSiteReview += '<li class="expand" id="liSiteReviewExpand" onclick="siteReviewExpand();" >'+ home_lang['expand'] +'</li>';
		
		strSiteEstimate += '<li class="expand" id="liSiteEstimateExpand" onclick="siteEstimateExpand();" >' + home_lang['expand'] + '</li>';
	}	
		
	$('#review_site').html(strSiteReview);
	$('#estimate-site').html(strSiteEstimate);
	
	if(numSiteCheck > 0)
	{
		$('#divEstimateSite').css('display', '');
		$('#trReviewSite').css('display', '');
	}
	else
	{
		$('#divEstimateSite').css('display', 'none');
		$('#trReviewSite').css('display', 'none');
	}
	
	if(isReturnListChannelId)
	{
		
		if(arrValueChecked.length > 0)
		{
			return arrValueChecked.join(',');
		}
		else
		{
			return '';
		}
	}
}

function suggCatCheckChannel(catid, type, isUpdateEstimate)
{
	type = (typeof(type) === 'undefined' || type === '') ? 1 : type;
	isUpdateEstimate = (typeof(isUpdateEstimate) === 'undefined' || isUpdateEstimate === '') ? true : isUpdateEstimate;
	if(type == 1) // add cat
	{
		var onSuccess = function(data)
		{
			var objData = jQuery.parseJSON(data);
			var num = objData.length;
			for(var i = 0; i < num; i++)
			{
				$('#site-channel-' + objData[i]).attr('checked', 'checked');
			}
			$('#hddListTargetSiteChannelId').val(listSiteSort(true, true));
			step2ShowSiteChannelError();
			if(isUpdateEstimate)
			{
				updateEstimate();
			}
		};
		getAjax('/home/get_site_channel_by_cat', 'catid=' + catid, '', '', '', false, onSuccess);
	}
	else if (type == 2) // remove cat
	{
		var onSuccess = function(data)
		{
			var objData = jQuery.parseJSON(data);
			var num = objData.length;
			for(var i = 0; i < num; i++)
			{
				$('#site-channel-' + objData[i]).attr('checked', '');
			}
			$('#hddListTargetSiteChannelId').val(listSiteSort(true, true));
			step2ShowSiteChannelError();
			if(isUpdateEstimate)
			{
				updateEstimate();
			}
		};
		getAjax('/home/get_site_channel_by_cat', 'catid=' + catid, '', '', '', false, onSuccess);
	}
	
}

// for suggest cat
function addSuggestCat(catid, tagid, obj, strInputDefault)
{
	strInputDefault = (typeof(strInputDefault) === 'undefined' || strInputDefault === '') ? '' : strInputDefault;
	var name = $('#suggest-other-cat-name-' + catid).html();
	$(tagid).siblings('.superblyTagInput').css({width: '0'});
	$(tagid).siblings('.superblyTagInput').val('');
	
	$(tagid).parent('.superblyTagInputItem').before("<li class='superblyTagItem'><span>" + name + "</span><a><img alt='' src='/images/x.gif' /></a><input type='hidden' class='superblyTagItemHddId' value='" + catid + "' /></li>");
	
	var val = $(tagid).val();
	if(val == '')
	{
		$(tagid).val(catid);	
	}
	else
	{
		$(tagid).val($(tagid).val() + ',' + catid);	
	}
	
	var new_index = $(tagid).parent('.superblyTagInputItem').parent('.superblyTagItems').children('.superblyTagItem').size()-1;	
	$($(tagid).parent('.superblyTagInputItem').parent('.superblyTagItems').children('.superblyTagItem')[new_index]).children('a').click(function(e){
		//var value = $($(this).parent('.superblyTagItem').children('span')[0]).text();
		var value = $($(this).parent('.superblyTagItem').children('.superblyTagItemHddId')).val();
		removeSuggestCat(value, tagid, strInputDefault);
	});
	$(obj).parent('.target-obj-sugg-item').remove();
	updateCatReview();
	//updateEstimate();
	step2ShowLikeErr();
	
	$('#targetSuggOtherCatLoading').css('display','');
	setTimeout('addSuggestCatUpdateData("' + strInputDefault +  '")', 1000);
	
	
	suggCatCheckChannel(catid, 1);
}

function addSuggestCatUpdateData(strInputDefault)
{
	strInputDefault = (typeof(strInputDefault) === 'undefined' || strInputDefault === '') ? '' : strInputDefault;
	var onSuccess = function(data)
	{
		var objData = jQuery.parseJSON(data);
		var num = objData.length;
		
		var arrCurr = $('#catSuggestOther').children('.target-obj-sugg-item');
		var arrCurrSuggId = new Array();
		for(var i = 0; i < arrCurr.length; i++)
		{
			arrCurrSuggId.push($(arrCurr[i]).children('input').val());
		}
		
		for(var i = 0; i < num; i++)
		{
			if(jQuery.inArray(objData[i].categoryid, arrCurrSuggId) == -1)
			{
				$('#catSuggestOther').append("<p class='target-obj-sugg-item' ><input type='checkbox' class='ver-middle marright5' value='" + objData[i].categoryid + "' onclick=\"addSuggestCat('" + objData[i].categoryid + "', '#txtTargetObject', this, '" + strInputDefault + "');\" /><span class='ver-middle' id='suggest-other-cat-name-" + objData[i].categoryid + "' >" + objData[i].name + "</span> </p>");
			}
		}
		$('#targetSuggOtherCatLoading').css('display', 'none');
		
	};
	getAjax('/home/get_suggest_cat_relate', 'currid=' + $('#txtTargetObject').val(), '', '', '', false, onSuccess);
}

function removeSuggestCat(value, tagid, strInputDefault)
{
	strInputDefault = (typeof(strInputDefault) === 'undefined' || strInputDefault === '') ? '' : strInputDefault;
	var arrCurrValue = $(tagid).val().split(',');
	var index = jQuery.inArray(value, arrCurrValue);
	if(index > -1)
	{
		arrCurrValue.splice(index,1);			
		var arrSelectedTag = $(tagid).parent('.superblyTagInputItem').parent('.superblyTagItems').children(".superblyTagItem");
		var numSelectedTag = arrSelectedTag.length;
		for(var i=0; i<numSelectedTag; i++)
		{
			if($(arrSelectedTag[i]).children('.superblyTagItemHddId').val() == value)
			{
				$(arrSelectedTag[i]).remove();
				break;
			}
		}
	}
	if(arrCurrValue.length == 0)
	{
		$(tagid).siblings('.superblyTagInput').css({width: '350px'});
		$(tagid).siblings('.superblyTagInput').val(strInputDefault);
	}
	$(tagid).val(arrCurrValue.join(','));
	updateCatReview();
	suggCatCheckChannel(value, 2);
	step2ShowLikeErr();
}

function addCatCallBackUpdateSuggetsCat(strInputDefault)
{
	strInputDefault = (typeof(strInputDefault) === 'undefined' || strInputDefault === '') ? '' : strInputDefault;
	var onSuccess = function(data)
	{
		var objData = jQuery.parseJSON(data);
		var num = objData.length;
		for(var i = 0; i < num; i++)
		{
			$('#catSuggestOther').prepend("<p class='target-obj-sugg-item' ><input type='checkbox' class='ver-middle marright5' value='" + objData[i].categoryid + "' onclick=\"addSuggestCat('" + objData[i].categoryid + "', '#txtTargetObject', this, '" + strInputDefault +  "');\" /><span class='ver-middle' id='suggest-other-cat-name-" + objData[i].categoryid + "' >" + objData[i].name + "</span> </p>");
		}
		var arr = $('#catSuggestOther').children('.target-obj-sugg-item');
		for(var i = num; i < arr.length; i++)
		{
			$(arr[i]).remove();
		}
		$('#targetSuggOtherCatLoading').css('display','none');
	};
	getAjax('/home/get_suggest_cat_relate', 'currid=' + $('#txtTargetObject').val(), '', '', '', false, onSuccess);
}
// for suggest cat

// end for new

// payment
function payment_checkout()
{
	var price = $.trim($('#txtPrice').val());
	//var email = $.trim($('#txtMail').val());
	
	price = price.replace(/,/, '');
	
	var chkPrice = true;
	if(!isIntNumber(price) && !(parseInt(price) > 0))
	{
		$('#errorPrice').html('Bạn hãy nhập giá trị thanh toán!');
		$('#errorPrice').show();
		$('#txtPrice').addClass('error-border');
		chkPrice = false;
	}
	else
	{
		$('#errorPrice').hide();
		$('#txtPrice').removeClass('error-border');
		chkPrice = true;
	}
	/*var error_email = validateEmail(email);
	var chkEmail = true;
	if(error_email != '')
	{
		$('#errorEmail').html(error_email);
		$('#errorEmail').show();
		$('#txtMail').addClass('error-border');
		chkEmail = false;
	}
	else
	{
		$('#errorEmail').hide();
		$('#txtMail').removeClass('error-border');
		chkEmail = true;
	}*/
	
	if(chkPrice)	//if(chkPrice && chkEmail)
	{
		$('#frmCheckOut').submit();
	}
}
// end payment


// create account
function account_checkuname()
{
	var uname = $.trim($('#username').val());
	var onSuccess = function(data)
	{
		var objData = jQuery.parseJSON(data);
		var chk = $.trim(objData.chk);
		if(chk.length > 0)
		{
			$('#uname_check').show();
			$('#errorUsername').show();
			$('#errorUsername').html(chk);
			$('#username').addClass('error-border');
		}
		else
		{
			$('#errorUsername').hide();
			$('#uname_check').hide();
			$('#username').removeClass('error-border');
		}
	};
	
	getAjax('/account/checkuname/?uname=' + uname, '', '', '', '', false, onSuccess);
}

function account_checkemail()
{
	var email = $.trim($('#email').val());
	var onSuccess = function(data)
	{
		var objData = jQuery.parseJSON(data);
		var chk = $.trim(objData.chk);
		if(chk == 0)
		{
			$('#errorEmail').show();
			$('#errorEmail').html('Email này đã tồn tại trên hệ thống!');
			$('#email').addClass('error-border');
		}
		else
		{
			$('#errorEmail').hide();
			$('#email').removeClass('error-border');
		}
	};
	
	getAjax('/account/checkemail/?email=' + email, '', '', '', '', false, onSuccess);
}

function phonenumber_validate(str)
{
	if (!isNaN(str)) return true;
	return false;
}

function signup_check()
{
	//account_checkuname(); account_checkemail();
	
	var uname = $.trim($('#username').val());
	var pass = $.trim($('#password').val());
	var repass = $.trim($('#repassword').val());
	
	var fullname = $.trim($('#fullname').val());
	
	var email = $.trim($('#email').val());
	
	var phone = $.trim($('#phone').val());
	var address = $.trim($('#address').val());
	
	var uname_error = validateUsername(uname);
	var pass_error = validatePassword(pass);
	var email_error = validateEmail(email);
	
	var captcha = $.trim($('#aCaptcha').val());
	
	if(uname_error == '') uname_error = $.trim($('#errorUsername').val());
	if(email_error == '') email_error = $.trim($('#errorEmail').val());
	
	var chkUserName = true;
	if(uname_error != '')
	{
		$('#errorUsername').html(uname_error);
		$('#errorUsername').show();
		$('#username').addClass('error-border');
		chkUserName = false;
	}
	else
	{
		$('#errorUsername').hide();
		$('#username').removeClass('error-border');
		chkUserName = true;
	}
	
	var chkPass = true;
	if(pass == '' || repass == '')
	{
		$('#errorPassword').html("Bạn chưa nhập Mật khẩu.");
		$('#errorPassword').show();
		$('#password').addClass('error-border');
		chkPass = false;
	}
	else if(pass != repass)
	{
		$('#errorPassword').html('Mật khẩu không trùng nhau, bạn hãy thử lại.');
		$('#errorPassword').show();
		$('#password').addClass('error-border');
		$('#repassword').addClass('error-border');
		chkPass = false;
	}
	else if( pass.length < 6 || pass.length > 64)
	{
		$('#errorPassword').html("Mật khẩu của bạn quá ngắn, độ dài mật khẩu từ 6-64 ký tự!");
		$('#errorPassword').show();
		$('#password').addClass('error-border');
		chkPass = false;
	}
	else
	{
		$('#errorPassword').hide();
		$('#password').removeClass('error-border');
		$('#repassword').removeClass('error-border');
		chkPass = true;
	}
	
	var chkEmail = true;
	if(email_error != '')
	{
		$('#errorEmail').html(email_error);
		$('#errorEmail').show();
		$('#email').addClass('error-border');
		chkEmail = false;
	}
	else
	{
		$('#errorEmail').hide();
		$('#email').removeClass('error-border');
		chkEmail = true;
	}
	
	var chkFullName = true;
	if(fullname == '')
	{
		$('#errorFullname').html('Bạn chưa nhập Họ tên.');
		$('#errorFullname').show();
		$('#fullname').addClass('error-border');
		chkFullName = false;
	}
	else
	{
		$('#errorFullname').hide();
		$('#fullname').removeClass('error-border');
		chkFullName = true;
	}
	
	var chkPhone = true;
	if(phone == '')
	{
		$('#errorPhone').html('Bạn chưa nhập Số điện thoại.');
		$('#errorPhone').show();
		$('#phone').addClass('error-border');
		chkPhone = false;
	}
	else if (!phonenumber_validate(phone))
	{
		$('#errorPhone').html('Số điện thoại phải là dạng số.');
		$('#errorPhone').show();
		$('#phone').addClass('error-border');
		chkPhone = false;
	}
	else
	{
		$('#errorPhone').hide();
		$('#phone').removeClass('error-border');
		chkPhone = true;
	}
	
	//check captcha
	var chkCaptcha = true;
	if(captcha == '')
	{
		$('#errorCaptcha').html('Bạn chưa nhập Mã chống Spam !');
		$('#errorCaptcha').show();
		$('#aCaptcha').addClass('error-border');
		chkCaptcha = false;
	}
	/*else
	{
		$('#errorCaptcha').hide();
		$('#aCaptcha').removeClass('error-border');
		chkCaptcha = true;
	}*/
	
	if(chkUserName && chkPass && chkEmail && chkFullName && chkPhone && chkCaptcha)
	{
		$('#frmSignUp').submit(); return;
		// use ajax
		var dataString = 'username='+uname+'&password='+pass+'&repassword='+repass+'&fullname='+fullname+'&email='+email+'&phone='+phone+'&address='+address+'&aCaptcha='+captcha+'&callback=1';
		var onSuccess = function(data)
		{
			//Show popup
			if(data != ''){
				var objData = jQuery.parseJSON(data);
				//alert(objData.captcha);
				if(!objData.captcha)
				{
					$('#errorCaptcha').html(objData.captcha_msg);
					$('#errorCaptcha').show();
					$('#aCaptcha').addClass('error-border');
					return false;
				}
				
				var chk = $.trim(objData.chk);
				$('body').append(chk+'<div id="fade"></div>');
				$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn();
				
				$(document).ready(function() {
					$('#fade').click(function() {
						$('#fade').fadeOut()
						return false;
					});
				});
			}
		};
		account_checkuname(); account_checkemail();
		getAjax('/account/signup',dataString,'','POST','',false,onSuccess);
	}
}

function account_update_check()
{
	var pass = $.trim($('#newpassword').val());
	var repass = $.trim($('#newrepassword').val());
	
	var fullname = $.trim($('#fullname').val());
	
	var email = $.trim($('#email').val());
	var email_error = validateEmail(email);
	
	var chkPass = true;
	if(pass != '')
	{
		var pass_error = validatePassword(pass);
		if(pass != repass)
		{
			$('#errorPassword').html('The passwords you entered do not match. Please try again.');
			$('#errorPassword').show();
			$('#newpassword').addClass('error-border');
			$('#newrepassword').addClass('error-border');
			chkPass = false;
		}
		else if( pass.length < 6 || pass.length > 64)
		{
			$('#errorPassword').html("The password is the wrong length.");
			$('#errorPassword').show();
			$('#newpassword').addClass('error-border');
			chkPass = false;
		}
		else
		{
			$('#errorPassword').hide();
			$('#newpassword').removeClass('error-border');
			$('#newrepassword').removeClass('error-border');
			chkPass = true;
		}
	}
	
	var chkEmail = true;
	if(email_error != '')
	{
		$('#errorEmail').html(email_error);
		$('#errorEmail').show();
		$('#email').addClass('error-border');
		chkEmail = false;
	}
	else
	{
		$('#errorEmail').hide();
		$('#email').removeClass('error-border');
		chkEmail = true;
	}
	
	var chkFullName = true;
	if(fullname == '')
	{
		$('#errorFullname').html('Please enter your fullname.');
		$('#errorFullname').show();
		$('#fullname').addClass('error-border');
		chkFullName = false;
	}
	else
	{
		$('#errorFullname').hide();
		$('#fullname').removeClass('error-border');
		chkFullName = true;
	}
	
	if(chkPass && chkEmail && chkFullName)
	{
		$('#frmChangeInfo').submit();
	}
}

function account_lostpass()
{
	var email = $.trim($('#email').val());
	var email_error = validateEmail(email);
	
	var chkEmail = true;
	if(email_error != '')
	{
		$('#errorEmail').html(email_error);
		$('#errorEmail').show();
		$('#email').addClass('error-border');
		chkEmail = false;
	}
	else
	{
		$('#errorEmail').hide();
		$('#email').removeClass('error-border');
		chkEmail = true;
	}
	if(chkEmail)
	{
		$('#frmLostPass').submit();
	}
}
// end creae account


/* tool tip */
function toannh_tooltip(e, strTipTitle, strTipBody, width, xOffset, yOffset)
{	
	width = (typeof(width) === 'undefined' || width === '') ? 200 : width;
	
	xOffset = (typeof(xOffset) === 'undefined' || xOffset === '') ? 40 : xOffset;
	
	yOffset = (typeof(yOffset) === 'undefined' || yOffset === '') ? 0 : yOffset;
	
	if(strTipTitle != '' || strTipBody != '')
	{
		$('#toannh-tooltip').width(width);
				
		$("#toannh-tooltip-title").html(strTipTitle);
		$("#toannh-tooltip-body").html(strTipBody);
		
		var ttipW = $('#toannh-tooltip').width();
		var ttipH = $('#toannh-tooltip').height();
		
		if((ttipW/ttipH) < 3)
		{
			ttipW = ttipH * 3;
			ttipW = (ttipW > 450) ? 450 : ttipW;
			$('#toannh-tooltip').width(ttipW);
		}
		
		//alert($('#toannh-tooltip-inner').html());
		var pos = $(e).offset();
		var eWidth = $(e).outerWidth();
		var eHeight = $(e).outerHeight();
		
		$("#toannh-tooltip").css('z-index','-1000000001');
		$("#toannh-tooltip").show();
						
		var ttop = pos.top + yOffset + eHeight;
		
		var tleft = pos.left - xOffset;
		var arrowPosLeft = xOffset - ($('#toannh-tooltip-arrow').outerWidth() / 2) + (eWidth / 2);
		
		var wheight = $(window).height();
		var wWidth = $(window).width();
		
		//var wScrollTop = $(window).scrollTop();
		
		var tooltipHeight = $('#toannh-tooltip').outerHeight();
		var tooltipWidth = $('#toannh-tooltip').outerWidth();
		
		if(tleft + tooltipWidth > wWidth)
		{
			var tmp = tleft + tooltipWidth - wWidth;
			tleft -= tmp;
			arrowPosLeft = arrowPosLeft + tmp;	
		}
		/*
		if(ttop + tooltipHeight > wheight + wScrollTop)
		{
			var tmp = ttop + tooltipHeight - wheight - wScrollTop;
			ttop -= tmp;
			$("#toannh-tooltip-arrow").css("left", (tmp - 3) + "px" );
		}
		else
		{
			$("#toannh-tooltip").css("background-position","left top");
		}
		*/
		$('#toannh-tooltip-arrow').css("left", arrowPosLeft + "px");
		$("#toannh-tooltip").css("top",ttop + "px");
		$("#toannh-tooltip").css("left",tleft + "px");
		$("#toannh-tooltip").css('z-index','1000000001');			
	}
}

function removeToannh_Tooltip()
{
	$("#toannh-tooltip").css('display','none');
	$("#toannh-tooltip-title").html('');
	$("#toannh-tooltip-body").html('');
}

function toannh_tooltip2(e, strTipTitle, strTipBody, width, xOffset, yOffset)
{	
	width = (typeof(width) === 'undefined' || width === '') ? 200 : width;
	
	xOffset = (typeof(xOffset) === 'undefined' || xOffset === '') ? 40 : xOffset;
	
	yOffset = (typeof(yOffset) === 'undefined' || yOffset === '') ? 0 : yOffset;
	
	if(strTipTitle != '' || strTipBody != '')
	{
		$('#toannh-tooltip2').width(width);
				
		$("#toannh-tooltip-title2").html(strTipTitle);
		$("#toannh-tooltip-body2").html(strTipBody);
		
		var ttipW = $('#toannh-tooltip2').width();
		var ttipH = $('#toannh-tooltip2').height();
		
		if((ttipW/ttipH) < 3)
		{
			ttipW = ttipH * 3;
			ttipW = (ttipW > 450) ? 450 : ttipW;
			$('#toannh-tooltip2').width(ttipW);
		}
		
		//alert($('#toannh-tooltip-inner').html());
		var pos = $(e).offset();
		var eWidth = $(e).outerWidth();
		var eHeight = $(e).outerHeight();
		
		$("#toannh-tooltip2").css('z-index','-1000000001');
		$("#toannh-tooltip2").show();
		
		var tooltipHeight = $('#toannh-tooltip2').outerHeight();
		var tooltipWidth = $('#toannh-tooltip2').outerWidth();
				
		var ttop = pos.top - yOffset - tooltipHeight;
		
		var tleft = pos.left - xOffset;
		var arrowPosLeft = xOffset - ($('#toannh-tooltip-arrow-down').outerWidth() / 2) + (eWidth / 2);
		
		var wheight = $(window).height();
		var wWidth = $(window).width();
		
		//var wScrollTop = $(window).scrollTop();
		
		
		if(tleft + tooltipWidth > wWidth)
		{
			var tmp = tleft + tooltipWidth - wWidth;
			tleft -= tmp;
			arrowPosLeft = arrowPosLeft + tmp;	
		}
		/*
		if(ttop + tooltipHeight > wheight + wScrollTop)
		{
			var tmp = ttop + tooltipHeight - wheight - wScrollTop;
			ttop -= tmp;
			$("#toannh-tooltip-arrow").css("left", (tmp - 3) + "px" );
		}
		else
		{
			$("#toannh-tooltip").css("background-position","left top");
		}
		*/
		$('#toannh-tooltip-arrow-down').css("left", arrowPosLeft + "px");
		$("#toannh-tooltip2").css("top",ttop + "px");
		$("#toannh-tooltip2").css("left",tleft + "px");
		$("#toannh-tooltip2").css('z-index','1000000001');			
	}
}

function removeToannh_Tooltip2()
{
	$("#toannh-tooltip2").css('display','none');
	$("#toannh-tooltip-title2").html('');
	$("#toannh-tooltip-body2").html('');
}

function tooltip_preview (e, boxId, xOffset, yOffset)
{
    $('.ttip-ad-preview').hide();
	xOffset = (typeof(xOffset) === 'undefined' || xOffset === '') ? 40 : xOffset;	
	yOffset = (typeof(yOffset) === 'undefined' || yOffset === '') ? 0 : yOffset;
	
	var ttipW = $(boxId).width();
	var ttipH = $(boxId).height();
		
	
	var pos = $(e).offset();
	var eWidth = $(e).outerWidth();
	var eHeight = $(e).outerHeight();
	
	$(boxId).css('z-index','-1000010');
	$(boxId).show();
					
	var ttop = pos.top + yOffset + eHeight;
	
	var tleft = pos.left - xOffset;
	var arrowWidth = $(boxId).children('.ttip-ad-preview-arrow').outerWidth();
	var arrowPosLeft = xOffset - (arrowWidth / 2) + (eWidth / 2);
	
	var wheight = $(window).height();
	var wWidth = $(window).width();
		
	var tooltipHeight = $(boxId).outerHeight();
	var tooltipWidth = $(boxId).outerWidth();
	
	if(tleft + tooltipWidth > wWidth)
	{
		var tmp = tleft + tooltipWidth - wWidth;
		tleft -= tmp;
		arrowPosLeft = arrowPosLeft + tmp;	
	}
	
	$(boxId).find('img.ttip-ad-preview-arrow').css("left", arrowPosLeft + "px");
	$(boxId).css("top",ttop + "px");
	$(boxId).css("left",tleft + "px");
	$(boxId).css('z-index','1000010');		
}

function tooltip_preview_remove(boxId)
{
	$(boxId).css('display','none');
}
/* end tool tip */

function payPopup(id) {
	id = '#' + id;
    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
    $('#mask').remove();
	$('body').append('<div id="mask"></div>');
	var mask = $('#mask');
    //Set height and width to mask to fill up the whole screen
    $(mask).css({'width':maskWidth,'height':maskHeight});
     
    //transition effect
    $(mask).fadeIn(500);   
    $(mask).fadeTo("fast",0.8); 
 
    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();
           
    //Set the popup window to center
    $(id).css('top',  winH/2-$(id).height()/2 + $(window).scrollTop());
    $(id).css('left', winW/2-$(id).width()/2);
 
    //transition effect
    $(id).fadeIn(500);

    //if mask is clicked
    $(mask).click(function () {
        $(this).hide();
        $(id).hide();
    });
}
function chkRunFromDay(obj)
{
	if($(obj).attr('checked'))
	{
		$('#campStartDate').attr('disabled', 'disabled').css('background-color', '#f3f3f3');
		$('#campEndDate').attr('disabled', 'disabled').css('background-color', '#f3f3f3');
	}
	else
	{
		$('#campStartDate').attr('disabled', '').css('background-color', '#fff');
		$('#campEndDate').attr('disabled', '').css('background-color', '#fff');
	}
}